package com.joysuch.wwyt.workflow.controller;


import com.joysuch.wwyt.core.common.ajax.ResultBean;
import com.joysuch.wwyt.core.enums.Status;
import com.joysuch.wwyt.workflow.entity.dto.WorkflowWatermarkSettingsDto;
import com.joysuch.wwyt.workflow.entity.vo.WorkflowWatermarksettingsVO;
import com.joysuch.wwyt.workflow.service.WorkflowWatermarkSettingsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zero
 * @since 2021-10-25
 */
@RestController
@RequestMapping("/workflow/workflow-watermarksettings")
@Api(tags="业务流程-打印模板水印配置")
@Slf4j
public class WorkflowWatermarkSettingsController {

    @Autowired
    private WorkflowWatermarkSettingsService workflowWatermarksettingsService;
    
    @ApiOperation("根据流程id获取水印配置")
    @GetMapping("/getWatermarkSettingByWorkflowId")
    public ResultBean getWatermarkSettingByWorkflowId(Long workflowId){
        try {
            WorkflowWatermarkSettingsDto result = workflowWatermarksettingsService.getWatermarkSettingByProcessId(workflowId);
            if (result != null) {
                return ResultBean.success(result);
            }
            return ResultBean.defaultSuccessResult();
        }catch (Exception e) {
            log.error("获取水印配置失败",e);
            return ResultBean.fail(Status.OBTAIN_WATERMARK_FAILED);
        }
    }
    
    @ApiOperation("新增水印配置")
    @RequestMapping("/saveWatermarkSetting")
    public ResultBean saveWatermarkSetting(@RequestBody WorkflowWatermarksettingsVO workflowWatermarksettingsVO){
        try {
            workflowWatermarksettingsService.addWatermarkSetting(workflowWatermarksettingsVO);
            return ResultBean.defaultSuccessResult();
        }catch (Exception e){
            log.error("新增水印配置失败",e);
            return ResultBean.fail(Status.ADD_WATERMARK_FAILED);
        }
    }
    
}

